from machine import SoftI2C
from lib.config.index import sensor_config

sensors0 = sensor_config.get_sensor("ssd1306")
print(sensors0)
scl = sensors0["scl"]
sda = sensors0["sda"]

# You can choose any other combination of I2C pins
i2c = SoftI2C(scl, sda)

print("I2C SCANNER")
devices = i2c.scan()

if len(devices) == 0:
    print("No i2c device !")
else:
    print("i2c devices found:", len(devices))

    for device in devices:
        print("I2C hexadecimal address: ", hex(device))


def demo():
    import lib.net.wifi as wifi
    from lib.action import api
    from lib.sensors.oled import ops
    from utils import format

    wifi.do_connect_wifi()
    text = "54321"
    data_bytes = api.get_ssd1306_fonts(text.encode("utf-8"))
    fonts = format.format_network_response(data_bytes)
    print(fonts)
    font12 = fonts["font12"]
    ops.init_oled(scl, sda)
    ops.set_font(font12, 12)
    ops.reset_line()
    ops.show_text(text)


if __name__ == "__main__":
    demo()
